",
'removal_failed' => esc_html__( 'Removal Failed', 'imsanity' ),
'removal_succeeded' => esc_html__( 'Removal Complete', 'imsanity' ),
'operation_stopped' => esc_html__( 'Resizing stopped, reload page to resume.', 'imsanity' ),
'image' => esc_html__( 'Image', 'imsanity' ),
'invalid_response' => esc_html__( 'Received an invalid response, please check for errors in the Developer Tools console of your browser.', 'imsanity' ),
'none_found' => esc_html__( 'There are no images that need to be resized.', 'imsanity' ),
'resume_id' => $resume_id,
)
);
add_action( 'admin_notices', 'imsanity_missing_gd_admin_notice' );
add_action( 'network_admin_notices', 'imsanity_missing_gd_admin_notice' );
add_action( 'admin_print_scripts', 'imsanity_settings_css' );
}
/**
* Return true if the multi-site settings table exists
*
* @return bool True if the Imsanity table exists.
*/
function imsanity_multisite_table_exists() {
global $wpdb;
return $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->imsanity_ms'" ) === $wpdb->imsanity_ms;
}
/**
* Checks the schema version for the Imsanity table.
*
* @return string The version identifier for the schema.
*/
function imsanity_multisite_table_schema_version() {
// If the table doesn't exist then there is no schema to report.
if ( ! imsanity_multisite_table_exists() ) {
return '0';
}
global $wpdb;
$version = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'schema'" );
if ( ! $version ) {
$version = '1.0'; // This is a legacy version 1.0 installation.
}
return $version;
}
/**
* Returns the default network settings in the case where they are not
* defined in the database, or multi-site is not enabled.
*
* @return stdClass
*/
function imsanity_get_default_multisite_settings() {
$data = new stdClass();
$data->imsanity_override_site = false;
$data->imsanity_max_height = IMSANITY_DEFAULT_MAX_HEIGHT;
$data->imsanity_max_width = IMSANITY_DEFAULT_MAX_WIDTH;
$data->imsanity_max_height_library = IMSANITY_DEFAULT_MAX_HEIGHT;
$data->imsanity_max_width_library = IMSANITY_DEFAULT_MAX_WIDTH;
$data->imsanity_max_height_other = IMSANITY_DEFAULT_MAX_HEIGHT;
$data->imsanity_max_width_other = IMSANITY_DEFAULT_MAX_WIDTH;
$data->imsanity_bmp_to_jpg = IMSANITY_DEFAULT_BMP_TO_JPG;
$data->imsanity_png_to_jpg = IMSANITY_DEFAULT_PNG_TO_JPG;
$data->imsanity_quality = IMSANITY_DEFAULT_QUALITY;
$data->imsanity_delete_originals = false;
return $data;
}
/**
* On activation create the multisite database table if necessary. this is
* called when the plugin is activated as well as when it is automatically
* updated.
*/
function imsanity_maybe_created_custom_table() {
// If not a multi-site no need to do any custom table lookups.
if ( ! function_exists( 'is_multisite' ) || ( ! is_multisite() ) ) {
return;
}
global $wpdb;
$schema = imsanity_multisite_table_schema_version();
if ( '0' === $schema ) {
// This is an initial database setup.
$sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->imsanity_ms . ' (
setting varchar(55),
data text NOT NULL,
PRIMARY KEY (setting)
);';
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
// Add the rows to the database.
$data = imsanity_get_default_multisite_settings();
$wpdb->insert(
$wpdb->imsanity_ms,
array(
'setting' => 'multisite',
'data' => maybe_serialize( $data ),
)
);
$wpdb->insert(
$wpdb->imsanity_ms,
array(
'setting' => 'schema',
'data' => IMSANITY_SCHEMA_VERSION,
)
);
}
if ( IMSANITY_SCHEMA_VERSION !== $schema ) {
// This is a schema update. for the moment there is only one schema update available, from 1.0 to 1.1.
if ( '1.0' === $schema ) {
// Update from version 1.0 to 1.1.
$wpdb->insert(
$wpdb->imsanity_ms,
array(
'setting' => 'schema',
'data' => IMSANITY_SCHEMA_VERSION,
)
);
$wpdb->query( "ALTER TABLE $wpdb->imsanity_ms CHANGE COLUMN data data TEXT NOT NULL;" );
} else {
// @todo we don't have this yet
$wpdb->update(
$wpdb->imsanity_ms,
array( 'data' => IMSANITY_SCHEMA_VERSION ),
array( 'setting' => 'schema' )
);
}
}
}
/**
* Display the form for the multi-site settings page.
*/
function imsanity_network_settings() {
$settings = imsanity_get_multisite_settings(); ?>
' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '',
'wp help imsanity resize'
);
?>
' . esc_html__( 'List View in the Media Library', 'imsanity' ) . ''
);
?>
';
}
/**
* Multi-user config file exists so display a notice
*/
function imsanity_settings_page_notice() {
?>
" . esc_html__( 'The GD extension is not enabled in PHP, Imsanity may not function correctly. Enable GD or contact your web host for assistance.', 'imsanity' ) . '
';
}
/**
* Render the site settings form. This is processed by
* WordPress built-in options persistance mechanism
*/
function imsanity_settings_page_form() {
?>